package com.slkj.shilixiaoyuanapp.view.choosedialog;

import android.content.Context;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.slkj.shilixiaoyuanapp.R;

import java.util.ArrayList;
import java.util.List;

public class ChooseAdapter extends BaseQuickAdapter <ChooseBean ,BaseViewHolder> {

    private Context context;
    private List<ChooseBean> list = new ArrayList<>();

    public ChooseAdapter(@Nullable List<ChooseBean> list, Context context) {
        super(R.layout.item_choose, list);
        this.context = context;
        this.list = list;
    }

    @Override
    protected void convert(BaseViewHolder helper, ChooseBean item) {
        ImageView checkBox = helper.getView(R.id.check);
        if (item.isChoose()){
            checkBox.setImageResource(R.drawable.ic_checked);
        }else {
            checkBox.setImageResource(R.drawable.ic_un_checked);
        }
        TextView textView = helper.getView(R.id.name);
        textView.setText(item.getName());
        helper.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                item.setChoose(!item.isChoose());
                notifyItemChanged(helper.getAdapterPosition());
            }
        });
    }
}
